package com.longdaji.decoration.ui.activitiesOfMine.feedback;

import com.longdaji.decoration.base.RxPresenter;
import com.longdaji.decoration.bean.Account;
import com.longdaji.decoration.bean.Feedback;
import com.longdaji.decoration.data.DataManager;
import com.longdaji.decoration.data.network.CommonSubscriber;
import com.longdaji.decoration.utils.LogUtil;
import com.longdaji.decoration.utils.RxUtil;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by Kanade on 2018/5/2 0002.
 */

public class SeeFeedbackPresenter extends RxPresenter<SeeFeedbackContract.IView> implements SeeFeedbackContract.IPresenter {
    private DataManager mDataManager;

    private static final String TAG = "SeeFeedbackPresenter";

    @Inject
    public SeeFeedbackPresenter(DataManager dataManager) {
        this.mDataManager = dataManager;
    }

    @Override
    public void initData() {
        addSubscribe(mDataManager.doGetFeedbackApi(Account.getInstance().getUserid())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .compose(RxUtil.<Feedback>handleResult())
                .subscribeWith(new CommonSubscriber<Feedback>() {
                    @Override
                    public void onSuccess(Feedback feedback) {
                        LogUtil.d(TAG, "success  doGetFeedbackApi: " + feedback.getUserView().size());
                        List<Feedback.UserViewBean> userViewList = feedback.getUserView();
                        int length = userViewList.size();
                        List<Feedback.UserViewBean> tmpUserViewList = new ArrayList<>();
                        while (length > 0) {
                            length--;
                            tmpUserViewList.add(feedback.getUserView().get(length));
                        }
                        mView.showInitData(tmpUserViewList);

                    }

                    @Override
                    public void onFailed(String msg) {
                        LogUtil.d(TAG, "fail  doGetFeedbackApi: " + msg);
                    }
                }));
    }


}
